<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">通用大数据框架智能计算引擎优化仿真平台</el-breadcrumb-item>
      <el-breadcrumb-item>计算任务</el-breadcrumb-item>
      <el-breadcrumb-item>计算方案管理</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row :gutter="15">
        <el-col :span="8">
          <el-input placeholder="请输入内容" v-model="queryInfo.query"  class="input-with-select" clearable>
            <el-button slot="append" icon="el-icon-search" ></el-button>
          </el-input>
        </el-col>

        <el-col :span="3">
          <el-button type="primary"  @click="createCalculationTask" >创建计算方案</el-button>
        </el-col>
      </el-row>
      <el-table
          :data = "calculatschemeList"
          border
          style="width: 100%">
        <el-table-column
            prop="calculatschemename"
            label="计算方案名称"
            width="200">
        </el-table-column>

        <el-table-column
            prop="createtime"
            label="创建时间"
            width="200">
        </el-table-column>
        <el-table-column
            prop="updateman"
            label="创建人"
            width="200">
        </el-table-column>

        <el-table-column
            prop="operate"
            label="操作"
            width="360">
          <template  v-slot="scope">

            <el-tooltip class="item" effect="dark" content="编辑文件" placement="top">
              <el-button type="primary" icon="el-icon-edit"  @click="edit(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="删除文件" placement="top">
              <el-button type="danger" icon="el-icon-delete" @click="remove(scope.row)" ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
          title="创建计算"
          :visible.sync="createCalculationTaskVisble"
          width="20%"
          @close="closecreateCalculationTaskDialog"
      >
        <el-form :model="createCalculationTaskForm" :rules="createCalculationTaskFormRul" ref="createCalculationTaskFormRef" label-width="100px" class="demo-ruleForm">
          <el-form-item label="计算方案名称" prop="createCalculationTaskname">
            <el-input v-model="createCalculationTaskForm.createCalculationTaskname"></el-input>
          </el-form-item>
          <el-form-item label="选择计算"  >

            <el-select v-model="createCalculationTaskForm.checkedCalculation" prop="checkedCalculation" placeholder="请选择" :multiple = true :filterable="true">
              <el-option
                  v-for="item in Calculate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

        </el-form>
        <span slot="footer" class="dialog-footer">
     <el-button @click="createCalculationTaskVisble = false">取 消</el-button>
     <el-button type="primary" @click="createCalculationTaskSubmit">确 定</el-button>
     </span>
      </el-dialog>
      <el-dialog
          title="编辑文件"
          :visible.sync="editVisble"
          width="30%"
          @close="closeedDialog"
      >

        <el-form :model=" editParams"  :rules="editFormRul" ref="editParamsFormRef" label-width="100px" class="demo-ruleForm">
          <el-form-item label="文件名" prop="filename" >
            <el-input v-model="editParams.calculatschemename"  ></el-input>
          </el-form-item>

        </el-form>
        <span slot="footer" class="dialog-footer">
     <el-button @click="editVisble= false">取 消</el-button>
     <el-button type="primary" @click="editList">确 定</el-button>
     </span>
      </el-dialog>
    </el-card>
  </div>
</template>
<script>
export default {
  data(){

    return{
      queryInfo:{
        //查询参数
        query:'',
        pagenum:1,
        pagesize:10
      },
      editFormRul:{},
      editParams:{
        calculatschemename:'',calculatschemeid:''},
      createCalculationTaskFormRul:{},
      createCalculationTaskForm: {
        createCalculationTaskname:'',
        checkedCalculation:[],
      },

      Calculate:[],
      Calculatetest:[
        {
          value:'1',
          label:'计算1'
        },
        {
          value:'2',
          label:'计算2'
        }
      ],

      editVisble:false,
      createCalculationTaskVisble:false,
      calculatschemeList:[],
      calculatschemeListtset:[{
        calculatschemeid:'1',
        calculatschemename:'计算方案01',
        createtime:'2021',
        updateman:'z',
        path:''

      },

        {
          calculatschemeid:'2',
          calculatschemename:'计算方案02',
          createtime:'2021',
          updateman:'z',
          path:''

        }
  ],
    }
  },
  methods:{
    getCalculateSchemeList() {
      this.calculatschemeList = this.calculatschemeListtset
    },
    createCalculationTask(){
      this.$http.get('/').then(res=>{
        if(res.data.meta.status !== 200)
            // return this.$message.error('获取信息失败')

            //将这里的files等替换成数据库里的
          this.Calculate = this.Calculatetest


      })
    this.createCalculationTaskVisble = true
    },
    closecreateCalculationTaskDialog(){
      this.$refs.createCalculationTaskFormRef.resetFields()
    },
    createCalculationTaskSubmit(){
      this.$refs.createCalculationTaskFormRef.validate(valid=>{
        if(!valid) return alert('请输入正确信息')
      })
      this.$http.post('/',this.createCalculationTaskForm).then(res=>{
        console.log(res)

      })
      this.createCalculationTaskVisble = false
      this.getCalculateSchemeList()
    },
    edit(row){
      this.editParams = row
      this.editVisble = true
      // this.$http.get(`/${row.id}`).then(res=>{
      //   this.editFileParamse= res
      //
      //
      // })
    },
    remove(row){
      this.$confirm('此操作将永久删除'+row.calculatschemename+', 是否继续?', '删除文件', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.delete(`/${row.calculatschemeid}`).then(res=>{
          if(res.data.meta.status !== 200) return this.$message.error('删除失败')
          this.$message.success('删除成功')
          this.getCalculateSchemeList()
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    closeedDialog(){
      this.$refs.editParamsFormRef.resetFields()
    },
    editList(){
      this.$http.put(`/${this.editParams.calculatschemeid}`,this. editParams).then(res=>{
        if(res.data.meta.status !== 200) return this.$message.error('更新失败')
        this.getCalculateSchemeList()
        this.editVisble = false
      })
    }
  },
  created() {
    this.getCalculateSchemeList()
  }
}
</script>
<style>

</style>
